package com.zkingsoft.actions.admin;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.anotations.RemoveRequestToken;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.model.BusParam;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.plugin.util.WebUtil;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.pojo.BusParamVo;
import com.zkingsoft.services.BusParamService;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2016-10-07 08:53
 */
@Controller
@RequestMapping(value = "admin/busParam")
public class BusParamController extends BaseController {

	@Resource
	private BusParamService currentService;

	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(BusParam busParam, PaginationVO pageVo) {
		return showList(currentService, busParam, pageVo);
	}

	/**
	 * 新增或者修改页面
	 */
	@RemoveRequestToken
	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(BusParam busParam) {
		if (busParam.getId() != null) {
			return modify(currentService, busParam, "busParam");
		} else {
			return add(currentService, busParam, "busParam");
		}
	}
	
	/**
	 * 修改
	 */
	@RequestMapping(value = "/modifyParamInfo")
	public @ResponseBody AjaxResult modifyParamInfo(BusParamVo busParams) {
		for (BusParam busParam: busParams.getParams()) {
			currentService.modify(busParam);
		}
		return new AjaxResult(AjaxResult.STATUS_OK,"","更新成功");
	}

	/**
	 * 进入修改界面
	 */
	@SaveRequestToken
	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		BusParam busParam;
		if (id != null) {
			busParam = currentService.findById(id);
			WebUtil.getRequest().setAttribute("obj", busParam);
		}
		return "admin/busParam-form";
	}

	/**
	 * 进入修改界面
	 */
	@SaveRequestToken
	@RequestMapping(value = "/toList")
	public String toList() {
		List<BusParam> busParams = currentService.findByModel(null);
		for (BusParam busParam : busParams) {
			WebUtil.getRequest().setAttribute(busParam.getCode(), busParam);
		}
		return "admin/busParam-form";
	}

	/**
	 * 删除
	 */
	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(currentService, keys);
	}

}